PrintHtmlCallback

public interface PrintHtmlCallback implements BrowserAsyncCallback<P, R>

This callback allows you to configure the print settings when printing HTML content.

To configure settings for printing PDF content use PrintPdfCallback.

In this callback you can configure the print settings. The workflow is the following:

  1. Find the required printer using the Printers interface. You can obtain an instance of Printers using the printers method.
  2. Get the current PrintJob from the printer.
  3. Configure the required settings for the print job using the PrintSettings interface provided by the settings method.
  4. Apply the configured settings using the PrintSettings.apply() method.
  5. Tell the browser to proceed with the printing using the configured settings: proceed.

The following example demonstrates a typical scenario:


browser.set(PrintHtmlCallback.class, (params, tell) -> {
    SystemPrinter<HtmlSettings> printer = params.printers().list().stream()
            .filter(p -> p.deviceName().equals("Microsoft XPS Document Writer"))
            .findFirst()
            .orElseThrow(() -> new IllegalStateException("The printer is not found."));
    PrintJob<HtmlSettings> printJob = printer.printJob();
    printJob.settings()
            .paperSize(ISO_A4)
            .enablePrintingHeaderFooter()
            .colorModel(BLACK)
            .apply();
    printJob.on(PrintCompleted.class, event ->
            System.out.println("Printing is completed: success = " + event.isSuccess()));
    tell.proceed(printer);
});

Use the cancel method to cancel printing.

Since

7.13

Types

Link copied to clipboard
public final class Action extends AsyncCallbackAction<R>
An action providing a response to the PrintHtmlCallback.
Link copied to clipboard
public interface Params
The parameters of the PrintHtmlCallback.

Functions

Link copied to clipboard
public abstract void on(P params, R tell)
Invoked when the callback needs a response for the given callback parameters.